package net.phoenix.repository;

import java.util.Comparator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

/**
* Jigsaw server
* 
* @author    <a href="shamphone@gmail.com">Li XiongFeng</a>
* @date      2012-1-2
* @version   1.0.0
*/
public class NodeOrderComparator implements Comparator<Node> {
    public NodeOrderComparator() {
    }

    public int compare(Node node1, Node node2) {
    	try{
        int result = (node1).getIndex()-(node2).getIndex();

        if(result!=0)
            return (node1).getIndex()-(node2).getIndex();
        else
            return (node1).getName().compareTo((node2).getName());
    	}catch(RepositoryException ex){
    		throw new RepositoryRuntimeException(ex);
    	}

    }

}
